<template>
    <div class="home" ref="homeRef">
        <van-nav-bar title="提现明细" left-text="" left-arrow @click-left="onClickLeft" :fixed="true" :placeholder="true" />
        <div class="tabs">
            <van-tabs v-model:active="active" @change="changeTabs">
                <van-tab title="全部"></van-tab>
                <van-tab title="待审核"></van-tab>
                <van-tab title="已审核"></van-tab>
                <van-tab title="已驳回"></van-tab>
            </van-tabs>
        </div>
        <div class="content">
            <div v-for="(i,index) in list" :key="index">
                <div class="item">
                    <div class="left">
                        <van-icon name="chat" color="#2CB9A4" size="24" class="mar-rig" />
                        <text class="useFunc">提现方式：{{i.type_data === '0'?'微信':i.type_data ===1?'支付宝':"银行卡"}}</text>
                    </div>
                    <div class="right">
                        <span class="mar-rig" style="color: #545454;">¥{{i.actual_receipt}}</span>
                        <span :style="{color: i.status ==='1'?'#2CB9A4':'#FF6666'}">{{i.status === '0'?'待审核':i.status ==='1'?'已审核':'已驳回'}}</span>
                    </div>
                </div>
                <BorderDashed />
            </div>
            <noData :list="list" :lastPage="last_page" :page="page" />
        </div>
    </div>
</template>
<script setup>
import noData from "@/components/noData/noData.vue"
import BorderDashed from '@/components/border-dashed/border-dashed.vue'
import { useRouter } from 'vue-router'
import useScroll from '@/hooks/useScroll'
import { withdrawalList } from "@/services";
const router = useRouter();
import { onMounted, watch, ref } from 'vue';
const active = ref(0);
const list = ref([])
const status = ref(3)
const last_page = ref(1)
const page = ref(1)
const changeTabs = (i) => {
    list.value = []
    last_page.value = 0
    page.value = 1
    switch (i) {
        case 0:
        status.value = 3
            break;
        case 1:
        status.value = 0
            break;
        case 2:
        status.value = 1
            break;
        case 3:
        status.value = 2
            break;
        default:
        status.value = 3
    }
    getList()
}
// 监听滚动到底部
const homeRef = ref()
const { isReachBottom, scrollTop } = useScroll(homeRef)
console.log(homeRef.value)
watch(isReachBottom, (newValue) => {
    if (newValue) {
        if (page.value == last_page.value) {
            return
        } else {
            page.value++
            getList()
        }
    }
})
//获取列表
const getList = async () => {
    let res = await withdrawalList({ page: page.value, status: status.value })
    list.value = [...list.value, ...res.data.data]
    last_page.value = res.data.last_page
    console.log(list.value, last_page.value)
}
// 返回按钮
const onClickLeft = () => {
    router.back();
};
onMounted(() => {
    getList()
    // console.log(11111)
})
</script>
<style lang="scss" scoped>
::v-deep .van-tabs__line {
    background: #218CC9 !important;
}

::v-deep .van-tab--active {
    color: #2CB9A4 !important;
}

.tabs {
    position: sticky !important;
    top: 46px !important;
    z-index: 10 !important;
}

.home {
    background: #F6F6F6;
    height: 100vh;
    overflow-y: auto;
    box-sizing: border-box;
}
.content {
    padding: 20px;

    .item {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .left {
            color: #1D1B20;
            font-family: PingFang SC;
            font-size: 14px;
            font-style: normal;
            font-weight: 400;
            line-height: normal;
            display: flex;
            align-items: center;
        }

        .right {
            &:first-child {
                color: #545454;
                font-family: PingFang SC;
                font-size: 14px;
                font-style: normal;
                font-weight: 400;
                line-height: normal;
            }

            &:last-child {
                color: #F66;
                font-family: PingFang SC;
                font-size: 12px;
                font-style: normal;
                font-weight: 400;
                line-height: normal;
            }
        }

        .mar-rig {
            margin-right: 10px;
        }
    }
}
</style>